package Project;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.activation.DataSource;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

//import Connecting.ReTop_DepartVO;
//import Connecting.ReTop_ProfessorVO;


import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class ProfessorModify extends JPanel {

	private JTextField offices;
	private JTextField tf4;
	private JTextField tels;
	private JTextField names;
	private JTextField pws;
	private static Connection conn;
	private static PreparedStatement pstmt;
	private static ResultSet rs;
	
	

	public ProfessorModify() {

		setLayout(new BorderLayout(0, 0));

		// * TOP *

		makeTopPanel();

		// * CENTER *

		makeCenterPanel();

		// * BOTTOM *

		makeBottomPanel();

	} // ProfessorCapsulationLv1()

	private void makeTopPanel() {
		JPanel top = new JPanel();

		JLabel nlb1 = new JLabel("교수 개인정보 수정창"); // JLable( "ViewText") << 보여질
													// 텍스트 생성

		top.add(nlb1); // top 패널에 nlb1 JLabel을 추가

		add(top, BorderLayout.NORTH); // ProfessorCapsullationLv1 패널에 top 패널
										// 추가..

	}

	private void makeCenterPanel() {
		
		JPanel center = new JPanel();
		add(center, BorderLayout.CENTER);
		center.setLayout(new GridLayout(4, 2, 0, 0));
		
		JLabel pw = new JLabel("비밀 번호 :");
		center.add(pw);
				
				pws = new JTextField();
				center.add(pws);
				pws.setColumns(10);
		
				JLabel name = new JLabel("성명 :");
				center.add(name);
		
		names = new JTextField();
		center.add(names);
		names.setColumns(10);

		JLabel tel = new JLabel("연락처 :");
		center.add(tel);
	
		tels = new JTextField();
		center.add(tels);
		tels.setColumns(10);

		JLabel office = new JLabel("사무실 주소 :");
		center.add(office);

		offices = new JTextField();
		center.add(offices);
		offices.setColumns(10);

	}

	public void makeBottomPanel() {

		JPanel bottom = new JPanel();
		add(bottom, BorderLayout.SOUTH);

		JButton regbtn = new JButton("수정 완료");
		regbtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
						
				ReProfessorVO pv = new ReProfessorVO();
				pv.setProf_pw(pws.getText());
				pv.setProf_name(names.getText());
				pv.setProf_tel(tels.getText());
				pv.setProf_office(offices.getText());
				
				try{
					conn = ReJDBC_ConnClose.openDataBase();
					pstmt = conn.prepareStatement(ReJDBC_SQL.ProfessorUpdateSQL);
					pstmt.setString(1, pv.getProf_pw());
					pstmt.setString(2, pv.getProf_name());
					pstmt.setString(3, pv.getProf_tel());
					pstmt.setString(4, pv.getProf_office());
					pstmt.executeUpdate();
					JOptionPane.showMessageDialog(null, "정상적으로 등록되었습니다.");						
				}catch(Exception ex){
					ex.printStackTrace();
				}finally{
					ReJDBC_ConnClose.closeDataBase(conn, pstmt, rs);
				}
			}		
		});

		bottom.add(regbtn);

	}
	
}